﻿// JScript 文件
        
    var oWCBSpec;    
    var oWCBColor;
    //Ajax取得商品规格,将数据加载到下拉表格中
    function WCBSpec_InitializeCombo(webComboId)
    {
	    oWCBSpec = igcmbo_getComboById('WCBSpec');
	    oWCBSpec.getGrid().Bands[0].curTable=oWCBSpec.getGrid().Element;    //设定默认Band
    }

    function UWGDetail_BeforeEnterEditModeHandler(gridName, cellId)
    {
	    if (igtbl_getCellById(cellId).Column.Key=="GoodNorm")               //判断激活事件的列
	    {          
            LoadSpec(cellId);               
        }
        
        if(igtbl_getCellById(cellId).Column.Key=="GoodColor") 
        {
            LoadColor(cellId);
        }
        
    }

    function LoadSpec(cellId)
    {
        oWCBSpec.setDisplayValue("Re-Loading",false,false); 

  	    var goodid = igtbl_getCellById(cellId).Row.getCellFromKey("GoodID").getValue(); 
        Ajax.DepotIN.GetGoodSpec(goodid+"",LoadSpec_callback);              //异步(调用数据库中注册的方法)
    }

    function LoadSpec_callback(response) 
    {     
        while(oWCBSpec.grid.Rows.length>0)                                 //删除商品规格原有数据
        {  
            oWCBSpec.grid.Rows.remove(0); 
        } 
        var ds = response.value;     
        for(var i=0;i<ds.Tables[0].Rows.length;i++)                         //构建新表格
        {
            var row=oWCBSpec.getGrid().Rows.addNew(); 
            row.getCell(0).setValue(ds.Tables[0].Rows[i].SubString); 
        } 
        oWCBSpec.setDisplayValue("",false,false); 
    } 

    //Ajax取得商品颜色,将数据加载到下拉表格中
    function WCBColor_InitializeCombo(webComboId)
    {
        oWCBColor = igcmbo_getComboById('WCBColor');
	    oWCBColor.getGrid().Bands[0].curTable=oWCBColor.getGrid().Element;  //设定默认Band
    }

    function LoadColor(cellId)
    {
        oWCBColor.setDisplayValue("Re-Loading",false,false);     
  	    var goodid = igtbl_getCellById(cellId).Row.getCellFromKey("GoodID").getValue();
       
        Ajax.DepotIN.GetGoodColor(goodid+"",LoadColor_callback);              //异步(调用数据库中注册的方法)
    }

    function LoadColor_callback(response) 
    {     
        while(oWCBColor.grid.Rows.length>0)                                  //删除商品颜色原有数据
        {  
            oWCBColor.grid.Rows.remove(0); 
        } 
        var ds = response.value;     
        
        for(var i=0;i<ds.Tables[0].Rows.length;i++)  //构建新表格
        {       
            var row=oWCBColor.getGrid().Rows.addNew(); 
            row.getCell(0).setValue(ds.Tables[0].Rows[i].SubString); 
        } 
        oWCBColor.setDisplayValue("",false,false); 
    } 

    //Ajax取得商品价格

    function wgMain_AfterExitEditModeHandler(gridName, cellId)
    {
	    var goodid = igtbl_getCellById(cellId).Row.getCellFromKey("GoodID").getValue(); //获得GoodID
        var Price_Orig = Ajax.DepotIN.GetGoodPrice_Orig(goodid+"",LoadPrice_callback);                     //执行Ajax服务类方法
        
        if(igtbl_getCellById(cellId).Column.Key=="GoodNorm")//判断激活事件的列
        {
	        igtbl_getCellById(cellId).Row.getCellFromKey("Price_Orig").setValue(document.getElementById("Hidden3").value); //Ajax取数据过程
	    }
    }

    //取价格的回调方法
    function LoadPrice_callback(response)
    {
        document.getElementById("Hidden3").value = response.value;
    }


    //行更新之前进行校验
    function UWGDetail_BeforeRowUpdateHandler(gridName, rowId)
    {
        var ID = igtbl_getRowById(rowId).getCellFromKey("ID").getValue();
	    var goodId = igtbl_getRowById(rowId).getCellFromKey("GoodID").getValue();
	    var goodNorm = igtbl_getRowById(rowId).getCellFromKey("GoodNorm").getValue();
	    var goodColor = igtbl_getRowById(rowId).getCellFromKey("GoodColor").getValue();
	    var Amount = igtbl_getRowById(rowId).getCellFromKey("Amount").getValue();
	    var Price_Orig = igtbl_getRowById(rowId).getCellFromKey("Price_Orig").getValue();

        document.getElementById("Hidden2").value = "yes";
        if(goodId==null)
        {
            alert("商品不能为空！");
            
	        return false;
        }
        
        if(goodNorm==null)
	    {
	        alert("商品规格不能为空！");
	        document.getElementById("Hidden2").value = "";
	        return false;
	    }
    	
	    if(goodColor==null)
	    {
	        alert("商品颜色不能为空！");
	        document.getElementById("Hidden2").value = "";
	        return false;
	    }
    	
        if(Price_Orig==null)
	    {
	        alert("商品进货价格不能为空！");
	        document.getElementById("Hidden2").value = "";
	        return false;
	    }
    	
	    if(Amount==null || Amount < 1)
	    {
	        alert("商品数量格式不对，只能是大于零的正数！");
	        document.getElementById("Hidden2").value = "";
	        return false;
	    }

    }
